/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xui_lib.component.dialog.view;

import ohos.app.Context;

import com.xuexiang.xui_lib.component.dialog.config.ChooseBean;
import com.xuexiang.xui_lib.component.dialog.config.ConfigBean;
import com.xuexiang.xui_lib.component.dialog.config.DefaultConfig;
import com.xuexiang.xui_lib.component.dialog.interfaces.Assignable;
import com.xuexiang.xui_lib.component.dialog.interfaces.CheckBoxItemDialogListener;
import com.xuexiang.xui_lib.component.dialog.interfaces.DialogListener;
import com.xuexiang.xui_lib.component.dialog.interfaces.ItemDialogListener;

import java.util.ArrayList;

/**
 * description DialogAssigner
 *
 * @author liuluming
 * @since 2021-04-08
 */
public class DialogAssigner implements Assignable {

    private static DialogAssigner instance;

    private DialogAssigner() {

    }

    /**
     * 单例
     *
     * @return DialogAssigner
     */
    public static DialogAssigner getInstance() {
        if (instance == null) {
            instance = new DialogAssigner();
        }
        return instance;
    }


    @Override
    public ConfigBean assignMdAlert(Context context, CharSequence title, CharSequence msg, DialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.msg = msg;
        bean.title = title;
        bean.listener = listener;
        bean.type = DefaultConfig.ALERT_DIALOG;
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignTipAlert(Context context, CharSequence title, CharSequence msg, String submit, String cancel, DialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.msg = msg;
        bean.title = title;
        bean.submit = submit;
        bean.cancel = cancel;
        bean.listener = listener;
        bean.type = DefaultConfig.ALERT_DIALOG;
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignTipImageAlert(Context context, CharSequence title, CharSequence msg, String submit, String cancel, DialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.msg = msg;
        bean.title = title;
        bean.submit = submit;
        bean.cancel = cancel;
        bean.listener = listener;
        bean.type = DefaultConfig.ALERT_IMAGE_DIALOG;
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignMdIOSAlert(Context context, CharSequence title, CharSequence msg, DialogListener listener) {

        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.msg = msg;
        bean.title = title;
        bean.listener = listener;
        bean.type = DefaultConfig.IOS_ALERT_DIALOG;
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignMdIOSAlertVertical(Context context, CharSequence title, CharSequence msg, DialogListener listener) {

        ConfigBean bean = new ConfigBean();
        bean.context = context;

        bean.msg = msg;
        bean.title = title;
        bean.listener = listener;
        bean.type = DefaultConfig.IOS_VERTICAL_ALERT_DIALOG;
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignNormalInput(Context context, CharSequence title, CharSequence hint1,
                                        DialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.listener = listener;
        bean.title = title;
        bean.hint1 = hint1;
        bean.type = DefaultConfig.INPUT_DIALOG;
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignCountInput(Context context, CharSequence title, CharSequence hint1,
                                       DialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.listener = listener;
        bean.title = title;
        bean.hint1 = hint1;
        bean.type = DefaultConfig.INPUT_COUNT_DIALOG;
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignTwoInput(Context context, CharSequence title, CharSequence hint1, CharSequence hint2,
                                     DialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.listener = listener;
        bean.title = title;
        bean.hint1 = hint1;
        bean.hint2 = hint2;
        bean.type = DefaultConfig.TWO_INPUT_DIALOG;
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignMdSingleChoose(Context context, CharSequence title, ArrayList<ChooseBean> list,
                                           ItemDialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.title = title;
        bean.itemListener = listener;
        bean.type = DefaultConfig.SINGLE_DIALOG;
        bean.chooseBeans.addAll(list);
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignMySingleChoose(Context context, CharSequence title, String submit, String cancel,
                                           ArrayList<ChooseBean> list, ItemDialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.title = title;
        bean.itemListener = listener;
        bean.submit = submit;
        bean.cancel = cancel;
        bean.type = DefaultConfig.SINGLE_DIALOG;
        bean.chooseBeans.addAll(list);
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignMdIOSSingleMenuChoose(Context context, ArrayList<ChooseBean> list, int x, int y, int menuWidth, int menuHeight,
                                                  ItemDialogListener listener) {

        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.itemListener = listener;
        bean.type = DefaultConfig.SINGLE_MENU_DIALOG;
        bean.chooseBeans.addAll(list);
        bean.x = x;
        bean.y = y;
        bean.menuWidth = menuWidth;
        bean.menuHeight = menuHeight;
        bean.buildByType(bean);
        return bean;
    }


    @Override
    public ConfigBean assignMdIOSSingleChoose(Context context, ArrayList<ChooseBean> list,

                                              ItemDialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.itemListener = listener;
        bean.type = DefaultConfig.IOS_SINGLE_DIALOG;
        bean.chooseBeans.addAll(list);
        bean.buildByType(bean);
        return bean;
    }


    @Override
    public ConfigBean assignMdIOSBottomSingleChoose(Context context, ArrayList<ChooseBean> list,
                                                    ItemDialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.itemListener = listener;
        bean.type = DefaultConfig.IOS_BOTTOM_SINGLE_DIALOG;
        bean.chooseBeans.addAll(list);
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignMdIOSList(Context context, ArrayList<ChooseBean> list,
                                      ItemDialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.itemListener = listener;
        bean.type = DefaultConfig.IOS_LIST_DIALOG;
        bean.chooseBeans.addAll(list);
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignMdIMAGEList(Context context, ArrayList<ChooseBean> list,
                                        ItemDialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.itemListener = listener;
        bean.type = DefaultConfig.IMAGE_LIST_OTHER_DIALOG;
        bean.chooseBeans.addAll(list);
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignMdIOSListOther(Context context, ArrayList<ChooseBean> list,
                                           ItemDialogListener listener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.itemListener = listener;
        bean.type = DefaultConfig.IOS_LIST_OTHER_DIALOG;
        bean.chooseBeans.addAll(list);
        bean.buildByType(bean);
        return bean;
    }

    @Override
    public ConfigBean assignMdMultiChoose(Context context, CharSequence title, ArrayList<ChooseBean> list,
                                          CheckBoxItemDialogListener checkboxListener) {
        ConfigBean bean = new ConfigBean();
        bean.context = context;
        bean.msg = title;
        bean.title = title;
        bean.checkBoxItemDialogListener = checkboxListener;
        bean.type = DefaultConfig.MULTI_DIALOG;
        bean.chooseBeans.addAll(list);
        bean.buildByType(bean);

        return bean;
    }

}
